package ai.peanut.selfbase.common.exception;

import ai.peanut.selfbase.common.domain.DataResult;
import ai.peanut.selfbase.common.enums.ResultTypeEnum;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.UnauthorizedException;
import org.apache.shiro.session.UnknownSessionException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
@Slf4j
@ControllerAdvice
public class ControllerAdviceTest {

    @ExceptionHandler(UnauthorizedException.class)
    @ResponseBody
    public DataResult unauthorizedException(UnauthorizedException e) {
        log.info("---------无权限异常");
        return DataResult.faild(ResultTypeEnum.UNAUTHORIZED_EXCEPTION.getCode(),
                ResultTypeEnum.UNAUTHORIZED_EXCEPTION.getMessage());
    }
    @ExceptionHandler(UnknownSessionException.class)
    @ResponseBody
    public DataResult unknownSessionException(UnknownSessionException e) {
        log.info("---------session超时");
        return DataResult.faild(ResultTypeEnum.UNKNOWNSESSION_EXCEPTION.getCode(),
                ResultTypeEnum.UNKNOWNSESSION_EXCEPTION.getMessage());
    }


}
